package com.me.controller;


import com.me.service.VerifyCodeServiceImpl;
import com.me.util.JSONResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;

@Controller
class LoginController{
    @Resource
    private VerifyCodeServiceImpl verifyCodeService;

    @RequestMapping(value = "denglu", method = RequestMethod.POST)
    public String denglu(@ApiParam(name = "phone", value = "手机", required = true) String phone,
                          @ApiParam(name = "codes", value = "验证码", required = true) String codes) {

        JSONResult json = new JSONResult();
        try {
            boolean validate = verifyCodeService.validate(phone, codes);//验证手机号和验证码
            if (validate == false)
                json.setSuccess(false);
            else//验证成功，
            {
                return "success";
            }
            System.out.println(validate);
            //System.out.println(UserContext.getUserPhone().getIsBindPhone()+" kk ");
        } catch (Exception e) {
            json.setSuccess(false);
            json.setMsg(e.getMessage());
        }
        return  "error";

    }


    @RequestMapping(value = "sendVerifyCode", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult sendVerifyCode(@RequestBody String phone){//得到手机号

        JSONResult json = new JSONResult();
        try {
            this.verifyCodeService.sendVerifyCode(phone);
        } catch (Exception e) {
            json.setSuccess(false);
            json.setMsg(e.getMessage());
        }
        return json ;
    }


}
